package com.itboye.sunsun.adapter;

import java.util.ArrayList;

import com.itboye.sunsun.R;
import com.itboye.sunsun.address.ConversationModel;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ConversationAdapter extends BaseAdapter {
	ArrayList<ConversationModel> mlist;
	Context mcontext;

	public ConversationAdapter(ArrayList<ConversationModel> mlist,
			Context mcontext) {
		this.mlist = mlist;
		this.mcontext = mcontext;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mlist == null ? 0 : mlist.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mlist == null ? 0 : mlist.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View converView, ViewGroup paenrt) {
		// TODO Auto-generated method stub
		ConVerHandView mHandView;
		if (converView == null) {
			mHandView = new ConVerHandView();
			
			// /加载论坛评论内容item
			converView = LayoutInflater.from(mcontext).inflate(
					R.layout.forum_post_item, null);
			System.out.println(">>>>>>>>>>>>>>>>>>>>>>进入item");
			mHandView.text_item_convertion_name = (TextView) converView
					.findViewById(R.id.forum_text_name_post_item);
			mHandView.text_item_convertion_lou = (TextView) converView
					.findViewById(R.id.text_post_lou);
			mHandView.text_item_time = (TextView) converView
					.findViewById(R.id.text_post_time);
			mHandView.txt_item_content = (TextView) converView
					.findViewById(R.id.text_post_context);
			mHandView.Image_head = (ImageView) converView
					.findViewById(R.id.imageview_forum_post_item);
			mHandView.img_item_ping = (ImageView) converView
					.findViewById(R.id.img_forum_ping);
			mHandView.img_item_zan = (ImageView) converView
					.findViewById(R.id.img_item_zan);
			converView.setTag(mHandView);
		} else {
			mHandView = (ConVerHandView) converView.getTag();
		}

		// 对控件进行赋值
		mHandView.Image_head.setImageBitmap(mlist.get(position).getMhead());
		// 对登陆名进行
		
		mHandView.text_item_convertion_name.setText(mlist.get(position)
				.getName());
		// 是否是楼主
		mHandView.text_item_convertion_lou.setText(mlist.get(position)
				.getContxt());
		// 时间
		mHandView.text_item_time.setText(mlist.get(position).getTime());
		// 评论内容
		mHandView.txt_item_content.setText(mlist.get(position).getContent());
		
		mHandView.img_item_ping.setImageBitmap(mlist.get(position)
				.getMcomment());
		mHandView.img_item_zan.setImageBitmap(mlist.get(position).getMzambia());
		return converView;
	}

	class ConVerHandView {
		private TextView text_item_convertion_name;// 名字
		private TextView text_item_convertion_lou;// 是否是楼主
		private TextView text_item_time;// 评论时间
		private TextView txt_item_content;// 评论内容
		private ImageView Image_head;// 头像
		private ImageView img_item_ping;// 评论
		private ImageView img_item_zan;// 赞
	}

}
